from datetime import datetime

from django.contrib.auth.models import AbstractUser
from django.db import models


# Create your models here.
# 用户基础信息
class User(AbstractUser):
    # 用户头像
    user_image = models.ImageField(upload_to='user/', max_length=200, verbose_name='用户头像', null=True, blank=True)
    # 用户昵称
    nick_name = models.CharField(max_length=20, verbose_name='用户昵称', null=True, blank=True)
    # 用户的身份证号
    user_info = models.CharField(max_length=18, verbose_name='身份证号')
    # 出生年月
    birthday = models.DateTimeField(verbose_name='出生年月', null=True, blank=True)
    # 性别
    gender = models.CharField(choices=(('girl', '女'), ('boy', '男')), max_length=10, verbose_name='用户性别', default='boy')
    # 身高
    height = models.CharField(max_length=20, verbose_name='身高')
    # 体重
    weight = models.CharField(max_length=40, verbose_name='体重')
    # 民族
    nation = models.CharField(max_length=20, verbose_name='民族')
    # 信仰
    faith = models.CharField(max_length=20, verbose_name='信仰')
    # 家庭住址
    address = models.CharField(max_length=200, verbose_name='用户地址', null=True, blank=True)
    # 学科偏好
    subject_like = models.CharField(max_length=50, verbose_name='学科偏好')
    # 食物偏好
    food_like = models.CharField(max_length=50, verbose_name='食物偏好')
    # 健康状态
    health_status = models.CharField(max_length=20, verbose_name='健康状态')
    # 电话
    mobile = models.CharField(max_length=11, verbose_name='用户手机', unique=True)
    # 会员等级
    level = models.CharField(max_length=40, verbose_name='会员等级', null=False)
    # 星星数量
    stars_num = models.IntegerField(default=0, verbose_name='星星数量')
    # 创建时间
    add_time = models.DateTimeField(default=datetime.now, verbose_name='创建时间')

    def __str__(self):
        return self.username

    class Meta:
        db_table = 'users'
        verbose_name = '用户信息'
        verbose_name_plural = verbose_name


# 轮播图信息表
class BannerInfo(models.Model):
    # 轮播图图片
    image = models.ImageField(upload_to='banner/', verbose_name="轮播图片", max_length=200)
    # 轮播图网址
    url = models.URLField(default='http://www.bpmf.com', max_length=200, verbose_name="图片链接")
    # 添加时间
    add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间")

    def __str__(self):
        return str(self.image)

    class Meta:
        verbose_name = '轮播图信息'
        verbose_name_plural = verbose_name


# 用户地址管理表
class User_Address(models.Model):
    # 关联的用户
    user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='addresses', verbose_name='用户')
    # 收货人姓名
    receiver = models.CharField(max_length=20, verbose_name='收货人')
    # 收货人电话
    mobile = models.CharField(max_length=11, verbose_name='手机')
    # 收货人地址
    place = models.CharField(max_length=50, verbose_name='地址')
    # 收货人的详细地址
    detail_place = models.CharField(max_length=40, default=None, verbose_name='详细地址')
    # 默认地址
    default_address = models.CharField(max_length=50, null=True, blank=True,
                                       verbose_name='默认地址')
    # 是否删除
    is_deleted = models.BooleanField(default=False, verbose_name='逻辑删除')
    # 紧急联系人标识
    is_emergency_contact = models.BooleanField(default=False,verbose_name='是否紧急联系人')
    # 添加时间
    add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间")

    class Meta:
        verbose_name = '用户地址'
        verbose_name_plural = verbose_name
        ordering = ['add_time']
